<template>
<h2>录入病房</h2>
<table border="1">
    <tr>
        <td>病房名称</td>
        <td>
            <input type="text" v-model="info.WardName">
        </td>
    </tr>
    <tr>
        <td>床位</td>
        <td>
            <input type="number" v-model="info.WardBedNum">
        </td>
    </tr>
    <tr>
        <td>空床位</td>
        <td>
            <input type="number " v-model="info.KongBedNum">
        </td>
    </tr>
    <tr>
        <td>科室</td>
        <td>
            <select v-model="info.KeiShiId">
                <option :value="0">--请选择--</option>
                <option v-for="item in Kei" :value="item.KeiShiId">{{ item.KeiShiName }}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            <input type="button" value="录入" @click="SaveData">
        </td>
    </tr>
</table>

</template>
<script setup lang="ts">
import axios from "axios";
import { onMounted,ref } from "vue";

const info=ref({
    WardName:"",
    WardBedNum:"",
    KongBedNum:"",
    KeiShiId:0
})

const Kei=ref([{
    KeiShiId:0,
    KeiShiName:""

}])

//下拉框
onMounted(()=>{
    Lodata();
})

const Lodata=()=>{
    axios.get('https://localhost:7133/api/Ward/GetKeiShis')
    .then(res=>{
        Kei.value=res.data
    })
}


const SaveData=()=>{
    if(info.value.WardName==""){
        alert("病房名称不能为空");
        return;
    }
    if(info.value.WardName.length>6){
        alert("长度不能大于6");
        return;
    }

    axios.post('https://localhost:7133/api/Ward/AddWard',info.value)
    .then(res=>{
        if(res.data==-1){
            alert("病房已经存在");
        }
        else if(res.data>0){
            alert("录入成功");
        }
        else{
            alert("录入失败");
        }
    })
}

</script>